package com.jindy.module.syAccountStatement.controller;

import com.jindy.common.annotation.Log;
import com.jindy.common.core.controller.BaseController;
import com.jindy.common.core.domain.AjaxResult;
import com.jindy.common.core.page.TableDataInfo;
import com.jindy.common.enums.BusinessType;
import com.jindy.common.utils.poi.ExcelUtil;
import com.jindy.module.syAccountStatement.domain.SyAccountStatement;
import com.jindy.module.syAccountStatement.service.ISyAccountStatementService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 新对账单Controller
 * 
 * @author jindy
 * @date 2023-05-27
 */
@RestController
@RequestMapping("/module/syAccountStatement")
public class SyAccountStatementController extends BaseController
{
    private static final Logger LOGGER = LoggerFactory.getLogger(SyAccountStatementController.class);
    @Autowired
    private ISyAccountStatementService syAccountStatementService;

    /**
     * 查询新对账单列表
     */
    @PreAuthorize("@ss.hasPermi('module:syAccountStatement:list')")
    @GetMapping("/list")
    public TableDataInfo list(SyAccountStatement syAccountStatement)
    {
        startPage();
        List<SyAccountStatement> list = syAccountStatementService.selectSyAccountStatementList(syAccountStatement);
        return getDataTable(list);
    }

    /**
     * 导出新对账单列表
     */
    @PreAuthorize("@ss.hasPermi('module:syAccountStatement:export')")
    @Log(title = "新对账单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SyAccountStatement syAccountStatement)
    {
        List<SyAccountStatement> list = syAccountStatementService.selectSyAccountStatementList(syAccountStatement);
        ExcelUtil<SyAccountStatement> util = new ExcelUtil<SyAccountStatement>(SyAccountStatement.class);
        util.exportExcel(response, list, "新对账单数据");
    }

    /**
     * 获取新对账单详细信息
     */
    @PreAuthorize("@ss.hasPermi('module:syAccountStatement:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(syAccountStatementService.selectSyAccountStatementById(id));
    }

    /**
     * 新增新对账单
     */
    @PreAuthorize("@ss.hasPermi('module:syAccountStatement:add')")
    @Log(title = "新对账单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SyAccountStatement syAccountStatement)
    {
        try {
            return syAccountStatementService.insertSyAccountStatement(syAccountStatement);
        } catch (Exception e) {
            LOGGER.error("新增新对账单失败",e);
            return AjaxResult.error(e.getMessage());
        }
    }

    /**
     * 修改新对账单
     */
    @PreAuthorize("@ss.hasPermi('module:syAccountStatement:edit')")
    @Log(title = "新对账单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SyAccountStatement syAccountStatement)
    {
        return toAjax(syAccountStatementService.updateSyAccountStatement(syAccountStatement));
    }

    /**
     * 删除新对账单
     */
    @PreAuthorize("@ss.hasPermi('module:syAccountStatement:remove')")
    @Log(title = "新对账单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(syAccountStatementService.deleteSyAccountStatementByIds(ids));
    }
}
